<template>
  <div class="maskCenter">
    <div id="box" :class="visible?'systemDialog':'systemDialog'" style="height:564px;width:700px;">
      <div class="dialog-header" v-movew>
        <span>{{title}}</span>
        <el-tooltip class="item" effect="dark" content="关闭" placement="top-start">
          <span class="icon iconfont iconbiaoqianlan-guanbi close" @click="hide"></span>
        </el-tooltip>
      </div>
      <div class="dialog-body">
        <div class="role">
          <RoleTree
            :type="1"
            ref="roleTree"
            :dropMenuShow="0"
            @getNodeInfo="getNodeInfo"
            :propsParam="{parentId: 0,type: 1}"
          ></RoleTree>
        </div>
        <div class="tool">
          <div class="toolbtn" @click="addRoleitem">
            <i class="el-icon-right"></i>
          </div>
          <div class="toolbtn" @click="delRoleitem">
            <i class="el-icon-back"></i>
          </div>
          <div class="toolbtn" @click="Roleup">
            <i class="el-icon-top"></i>
          </div>
          <div class="toolbtn" @click="Roledown">
            <i class="el-icon-bottom"></i>
          </div>
        </div>
        <div class="selrole">
          <div
            class="div-item"
            v-for="(item,index) in info"
            @click="setRoleIndex(item,index)"
            :class="{'div-item-active':activeRoleItemIndex==index}"
          >{{item.roleName}}</div>
        </div>
      </div>
      <div class="dialog-footer right" style="margin-top:28px;">
        <span class="systemButtonConfirm" @click="okclick">确认</span>
        <span class="systemButtonConfirm" @click="hide">取消</span>
      </div>
    </div>
  </div>
</template>

<script>
import movew from "@/directives/winmove";
import RoleTree from "@/system/components/organizationTree";
import { deepCopy } from "@/utils/public";
export default {
  directives: { movew },
  name: "winRoleSelect",
  props: {
    activeRole: { default: null },
    operatetype: { default: null },
  },
  data() {
    return {
      visible: true,
      title: "角色编辑",
      info: [], //name:   value: "20"
      activeRoleItem: {},
      activeRoleItemIndex: -1,
      activeSelRoleItem: null,
    };
  },
  components: { RoleTree },
  mounted() {
    if (this.activeRole) {
      this.info = deepCopy(this.activeRole);
    } else {
    }
  },
  methods: {
    hide() {
      this.visible = false;
      setTimeout(() => {
        this.$emit("close");
      }, 400);
    },
    okclick() {
      this.visible = false;
      setTimeout(() => {
        this.$emit("ok", this.info, this.operatetype);
      }, 400);
    },
    getNodeInfo(e) {
      if (e.type == 1) {
        this.activeSelRoleItem = e;
      } else {
        this.activeSelRoleItem = null;
      }
    },
    setRoleIndex(item, index) {
      //保存当前点击的Flowitem  和 索引
      this.activeRoleItemIndex = index;
      this.activeRoleItem = item;
    },
    existRole(id) {
      //判断当前的tab是否存在
      let res = false;
      if (this.info) {
        this.info.forEach((item, index) => {
          if (item.roleId == id) {
            res = true;
          }
        });
      }
      return res;
    },
    addRoleitem() {
      //从数据库的表名新增到 cellinfo.wf
      if (this.activeSelRoleItem) {
        if (!this.existRole(this.activeSelRoleItem.id)) {
          let temp = {
            roleId: this.activeSelRoleItem.id,
            roleName: this.activeSelRoleItem.name,
          };
          this.info.push(temp);
        }
      }
    },
    delRoleitem() {
      //删除选中的Role
      if (JSON.stringify(this.activeRoleItem) != "{}") {
        //如果
        if (this.existRole(this.activeRoleItem.roleId)) {
          this.info.splice(this.activeRoleItemIndex, 1);
        }
        this.activeRoleItem = {};
        this.activeRoleItemIndex = -1;
      }
    },
    Roleup() {
      //Role位置上移
      if (this.activeRoleItemIndex > 0) {
        if (JSON.stringify(this.activeRoleItem) != "{}") {
          let temp = this.info[this.activeRoleItemIndex - 1];
          this.info[this.activeRoleItemIndex - 1] = this.info[
            this.activeRoleItemIndex
          ];
          this.info[this.activeRoleItemIndex] = temp;
          this.activeRoleItemIndex = this.activeRoleItemIndex - 1;
        }
      }
    },
    Roledown() {
      //表位置下移
      if (this.activeRoleItemIndex < this.info.length) {
        if (JSON.stringify(this.activeRoleItem) != "{}") {
          let temp = this.info[this.activeRoleItemIndex + 1];
          this.info[this.activeRoleItemIndex + 1] = this.info[
            this.activeRoleItemIndex
          ];
          this.info[this.activeRoleItemIndex] = temp;
          this.activeRoleItemIndex = this.activeRoleItemIndex + 1;
        }
      }
    },
  },
};
</script>

<style scoped>
.mask {
  height: 100%;
  width: 100%;
  position: fixed;
  top: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.3);
  z-index: 99;
  display: flex;
  align-items: center;
  justify-content: center;
}

.header {
  display: flex;
  justify-content: space-between;
  height: 40px;
  line-height: 40px;
  background: var(--win-head-back-color);
  margin: 4px;
  text-align: left;
}
.header .title {
  width: calc(100% - 25px);
  height: 40px;
  line-height: 40px;
  font-size: 16px;
  font-family: Microsoft YaHei;
  font-weight: 400;
  color: var(--system-page-topbar-text-color);
  margin-left: 12px;
}
.header .close {
  font-size: 12px;
  width: 12px;
  height: 12px;
  margin-right: 9px;
}

.dialog-body {
  display: flex;
  width: 100%;
  padding: 12px 17px;
  padding-bottom: 0px;
  height: calc(100% - 127px);
  color: var(--system-page-topbar-text-color);
}

/*表单背景宽高设置*/
.open-content {
  background: var(--win-page-back-color);
  box-shadow: 0px 10px 20px 0px var(--win-page-shadow-color),
    0px -10px 20px 0px var(--win-page-shadow-color);
  border-radius: 4px;
  overflow: hidden;
  animation: myscale 0.4s;
}

/*表单打开动画*/
@keyframes myscale {
  0% {
    opacity: 0;
    transform: scale(0.6);
  }

  100% {
    opacity: 1;
    transform: scale(1);
  }
}

/*表单关闭样式及动画*/
.open-content-hide {
  background: var(--win-page-back-color);
  box-shadow: 0px 10px 20px 0px var(--win-page-shadow-color),
    0px -10px 20px 0px var(--win-page-shadow-color);
  border-radius: 4px;
  overflow: hidden;
  animation: myscalehide 0.4s;
  transform: scale(0.6);
  opacity: 0;
}

@keyframes myscalehide {
  0% {
    opacity: 1;
    transform: scale(1);
  }

  100% {
    opacity: 0;
    transform: scale(0.6);
  }
}

@keyframes fadeInLeft {
  0% {
    opacity: 0;
    transform: translateX(-120px);
  }

  100% {
    opacity: 1;
    transform: translateX(0);
  }
}

.body-row {
  display: flex;
  line-height: 32px;
  height: 32px;
  margin-top: 10px;
  width: 100%;
}
.row-content {
  margin-left: 15px;
  width: 227px;
}
/*element 输入框样式*/
>>> .el-input__inner {
  line-height: 32px;
  height: 32px;
  width: 227px;
  border: 1px solid var(--input-border-color);
  border-radius: 4px;
  color: var(--input-text-color);
  font-size: 14px;
  font-family: Microsoft YaHei;
  font-weight: 400;
}
/*element 下拉框*/
>>> .el-input__inner:focus {
  border: 1px solid var(--input-focus-border-color);
}
/*下拉框箭头*/
>>> .el-select__caret {
  line-height: 32px;
}
>>> .el-select {
  width: 227px;
}
/*element 输入框的 focus hover样式*/
>>> .el-input__inner:focus,
>>> .el-textarea__inner:focus {
  background: var(--input-focus-back-color);
  border: 1px solid var(--input-focus-border-color);
  border-radius: 4px;
}

>>> .el-input__inner:hover,
>>> .el-textarea__inner:hover {
  background: var(--input-hover-back-color);
  border: 1px solid var(--input-focus-border-color);
}
>>> .el-textarea__inner {
  color: var(--input-text-color);
  font-size: 14px;
  font-family: Microsoft YaHei;
  font-weight: 400;
}
.footer {
  padding-right: 20px;
  height: 60px;
  line-height: 60px;
  display: flex;
  flex-direction: row;
  justify-content: flex-end;
  margin-bottom: 20px;
}
.label-name {
  width: 60px;
  text-align: left;
}
.role {
  height: 100%;
  width: calc(50% - 26px);
  border: 1px solid var(--button-border-color);
  border-radius: 4px;
  overflow: auto;
  background: var(--page-back-color);
}
.tool {
  height: 100%;
  width: 52px;
  padding-top: 131px;
}
.selrole {
  height: 100%;
  width: calc(50% - 26px);
  border: 1px solid var(--button-border-color);
  border-radius: 4px;
  overflow: auto;
  background: var(--page-back-color);
}
.toolbtn {
  margin-left: 10px;
  border: 1px solid var(--button-border-color);
  border-radius: 4px;
  width: 32px;
  height: 32px;
  line-height: 32px;
  margin-bottom: 10px;
  color: rgba(144, 162, 175, 1);
}
.toolbtn:hover {
  background: var(--button-hover-back-color);
  color: var(--button-active-text-color);
  cursor: pointer;
}
.toolbtn:active {
  background: var(--button-active-back-color);
  color: var(--button-active-text-color);
  cursor: pointer;
}

>>> .el-tree {
  height: 423px;
}
/*/选表  选记录的 样式*/
.div-item {
  width: 302px;
  height: 32px;
  line-height: 32px;
  padding: 0px 9px;
  text-align: left;
}
.div-item:hover {
  background: var(--button-hover-back-color);
  color: var(--button-active-text-color);
  cursor: pointer;
}
.div-item-active {
  background: var(--button-active-back-color);
  color: var(--button-active-text-color);
  cursor: pointer;
}
</style>